package com.kongwg.java2;

import java.util.concurrent.*;

/**
 * 创建綫程的方式四： 线程池
 * @author kongwg
 * @create 2020-12-05 22:00
 */

class Numberthread implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i%2 ==0){
                System.out.println(Thread.currentThread().getName() + "  :"+ i);
            }
        }
    }
}
class Numberthread1 implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            if (i%2 !=0){
                System.out.println(Thread.currentThread().getName() + i);
            }
        }
    }
}
class  Mysubmit implements Callable{


    @Override
    public Object call() throws Exception {
        System.out.println("wo shi  submit");
        return "kongwg";
    }
}
public class ThreadPool {
    public static void main(String[] args) {
        ExecutorService service = Executors.newFixedThreadPool(10);
        Numberthread numberthread = new Numberthread();
        Numberthread1 numberthread1 = new Numberthread1();
//        service.execute(numberthread);
//        service.execute(numberthread1);
        Future submit = service.submit(new Mysubmit());
        try {
            System.out.println(submit.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        service.shutdown();
    }
}
